import feedparser
import pandas as pd

def get_category(file_name):
    # 读取Excel文件
    df = pd.read_excel(file_name)

    # 获取category列的所有去重元素
    category_column = df['category']
    unique_categories = category_column.unique()

    # 打印去重元素列表
    for category in unique_categories:
        print(category)
    # 定义类别映射关系
    categories = [
        ('Technology 科技', '59'),
        ('Blog 博客', '60'),
        ('Design 设计', '61'),
        ('人文社科', '62'),
        ('Programming 技术', '63'),
        ('播客', '64'),
        ('Product 产品', '65'),
        ('News 新闻资讯', '66'),
        ('Arts 文学', '67'),
        ('艺术', '68'),
        ('Entertainment 书影音', '69'),
        ('Sciense 科普', '70'),
        ('建筑', '71'),
        ('商业资讯', '72'),
        ('ACG', '73'),
        ('时尚', '74'),
        ('体育', '75'),
        ('哲学', '76'),
        ('摄影', '77'),
        ('科普', '78'),
        ('股市', '79'),
        ('Humanities 人文社科', '80')
    ]

    # 创建映射字典
    category_mapping = {name: code for name, code in categories}

    # 添加新一列并根据映射关系赋值
    df['category_code'] = df['category'].map(category_mapping)

    # 保存更新后的 Excel 文件
    df.to_excel('new_file.xlsx', index=False)
def parser_rss():
    # 解析 RSS 源
    feed_url = "https://www.twreporter.org/a/rss2.xml"
    feed = feedparser.parse(feed_url)

    # 打印 RSS 源的标题和描述
    print("Feed Title:", feed.feed.title)
    print("Feed Description:", feed.feed.description)
    # feed.feed.link: RSS 源的链接
    # feed.feed.updated: RSS 源的最后更新时间
    # feed.feed.author: RSS 源的作者
    # feed.feed.language: RSS 源使用的语言

    # 打印每个条目的标题和链接
    for entry in feed.entries:
        print("Entry Title:", entry.title)
        print("Entry Link:", entry.link)
        print("Entry update:", entry.updated)
        if 'author' in entry:
            print("Entry Author:", entry.author)
        else:
            print("Author information not available for this entry.")

get_category('RSS_Source.xlsx')

